<?php
$userInfo = $_GET["userInfo"];
?>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<?php
if(!isset($userInfo)){
    ?>
    <script type="text/javascript">
        var user = '';
        user += "appCodeName='" + navigator.appCodeName + "' ";
        user += "appName='" + navigator.appName + "' ";
        user += "appVersion='" + navigator.appVersion + "' ";
        user += "language='" + navigator.language + "' ";
        user += "userAgent='" + navigator.userAgent + "' ";

        location.href = "?userInfo=" + user;
    </script>
    <?php
}else{
    $position = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
    ?>
    <p id="demo"></p>
    <p><?=$userInfo?></p>
    <p>Remote Address: <?=$_SERVER['REMOTE_ADDR']?></p>
    <p>País: <?=$position["geoplugin_countryName"]?></p>
    <script type="text/javascript">  
        var x=document.getElementById("demo");
        function showPosition(position){
          x.innerHTML = "Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude;	
        }
        navigator.geolocation.getCurrentPosition(showPosition);
    </script>
    <?php
}
?>
</body>
</html>
